package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.WxBrandVo;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.cskaoyan.service.WxBrandService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌模块
 * @author Fyy
 * @since 2023/01/01 17:04
 */

@RestController
@RequestMapping("wx/brand")
public class WxBrandListController {

    @Autowired
    WxBrandService brandService;

    /**
     * 品牌列表
     * @param basePageInfo
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo basePageInfo) {
        //根据传入数据查询
        CommonData<MarketBrand> data = brandService.list(basePageInfo);
        //获取品牌数据list
        List<MarketBrand> brandList = data.getList();
        //封装返回值需要的list
        List<WxBrandVo> list = new ArrayList<>();
        for (MarketBrand marketBrand : brandList) {
            //判空
            if (!ObjectUtils.isEmpty(marketBrand)) {
                WxBrandVo wxBrandVo = new WxBrandVo();
                BeanUtils.copyProperties(marketBrand, wxBrandVo);
                list.add(wxBrandVo);
            }
        }
        //封装返回值
        CommonData<WxBrandVo> wxData = new CommonData<>();
        BeanUtils.copyProperties(data,wxData);
        wxData.setList(list);
        return BaseRespVo.ok(wxData, "成功");
    }

    /**
     * 品牌详情
     * @param id
     * @return
     */
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        //根据id查询品牌详情
        MarketBrand detail = brandService.detail(id);
        return BaseRespVo.ok(detail, "成功");
    }
}
